package be.ipl.diavoloz.daoimpl;

import java.util.Iterator;
import java.util.List;

import javax.ejb.Stateless;

import be.ipl.diavoloz.dao.DemonsDao;
import be.ipl.diavoloz.modele.Couleur;
import be.ipl.diavoloz.modele.De;
import be.ipl.diavoloz.modele.Demons;

@SuppressWarnings("serial")
@Stateless
public class DemonsDaoImpl extends DaoImpl<Integer, Demons> implements DemonsDao{

	@Override
	public Demons chercherParNom(String nom) {
		String queryString = "select d from Demons d where d.nom = ?1";
		return recherche(queryString, nom);
	}

	@Override
	public List<Demons> chercherParCouleur(Couleur couleur) {
		String queryString = "select d from Demons d where d.couleur = ?1";
		return liste(queryString, couleur);
	}

	@Override
	public Demons chercherParId(int id) {
		String queryString = "select d from Demons d where d.id = ?1";
		return recherche(queryString, id);
	}
	
	@Override
	public List<Demons> chercherParTour(int idTour) {
		String queryString = "select d from Demons d where d.demons_tour = ?1";
		return liste(queryString, idTour);
	}


	@Override
	public void supprimerTable() {
		String queryString = "SELECT d from Demons";
		List<Demons> l = liste(queryString, null);
		Iterator<Demons> it = l.iterator();
		while(it.hasNext()){
			Demons d = (Demons) it.next();
			supprimer(d.getId());
		}	
	}

}
